Skip to content

Conversation

@wrefgtzweve
Copy link
Member

Fixes saving issues when spaces are used

Getting filename for path: advdupe2/tests/      d
Attempt to open dangerous file path! Blocking: '\garrysmod\data\advdupe2\tests\ d.txt'.
Attempt to open dangerous file path! Blocking: '\garrysmod\data\advdupe2\tests\daw d .txt'.
[AdvDupe2Notify]    File was not saved! (Could not open file for writing)

@marchc1
Copy link
Contributor

marchc1 commented Oct 22, 2025

@wrefgtzweve I'm not a fan of this being the solution to the problem, because if I remember correctly advdupe2 used to have this restriction, but removed it. Why reintroduce the restriction again instead of addressing the actual problem with periods and spacing?

It seems like just in general, the function doesnt like leading/trailing spaces after a dot. You could use a gsub to handle that; "%s*%.%s*" and gsub with "." would be enough

@marchc1
Copy link
Contributor

marchc1 commented Oct 22, 2025

local tests = {
    "test. test.txt",
    "test .test.txt",
    "test . test.txt",
    "test   . test.txt",
    "test .       .       .        test.txt",
}

for _, test in ipairs(tests) do
    local fixed = test:gsub("%s*%.%s*", "."):gsub("%.%.+", ".")
    print(test, "->", fixed, " - file.Write result ", file.Write(fixed, "nothing"))
end

Adding the second gsub would handle multiple periods too which file.Write also doesn't like

@wrefgtzweve
Copy link
Member Author

@wrefgtzweve I'm not a fan of this being the solution to the problem, because if I remember correctly advdupe2 used to have this restriction, but removed it. Why reintroduce the restriction again instead of addressing the actual problem with periods and spacing?

It seems like just in general, the function doesnt like leading/trailing spaces after a dot. You could use a gsub to handle that; "%s*%.%s*" and gsub with "." would be enough

Yeah i agree, i've improved it

@wrefgtzweve wrefgtzweve changed the title Replace spaces with _ for filepaths, sanitize in GetFilename too Fix AdvDupe2.SanitizeFilename not catching all cases, sanitize in GetFilename too Oct 22, 2025
@Astralcircle Astralcircle merged commit 2f73595 into wiremod:master Oct 23, 2025
1 check failed
@wrefgtzweve wrefgtzweve deleted the prevent-invalid-files branch November 18, 2025 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants